package btc.backend.process;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Statement;

public class TestConexionDB {

    /**
     * @param args
     * @throws Throwable
     */
    public static void main(String[] args) throws Throwable {

        java.sql.ResultSet result = null;
        Connection conexion = ConnectionFactory.getConnection();

        Statement st = conexion.createStatement();

        DatabaseMetaData dbmd = conexion.getMetaData();
        //si no existe la tabla, corro los DDL
        ResultSet rs = (ResultSet)dbmd.getTables(null, ConnectionFactory.DB_NAME, "bloque", null);
        if(!rs.next())
        {
            ScriptRunner runner = new ScriptRunner(conexion, true, true);
            InputStream inputStream = TestConexionDB.class.getClassLoader().getResourceAsStream("DDL.sql");
            runner.runScript(new InputStreamReader(inputStream));
        }

        result = st.executeQuery("select ID,ID_PALLET,ALTO,ANCHO,LARGO from bloque");

        while (result.next()) {
            System.out.println(result.getInt(1) + ";"
                    + result.getInt(2) + ";"
                    + result.getFloat(3) + ";"
                    + result.getFloat(4) + ";"
                    + result.getFloat(5));
        }

        result.close();


    }

}
